
const TechProduct = {
    page: 1,
    cateId: 0,
    getProductCatList: function () {
        let _this = this
        _this.cateId = common.getQueryString("cateId") || '0'
        ajax_get(host + `/ajax/productsCate`,
            true,
            {},
            (res) => {
                res = JSON.parse(res)
                console.log(res)
                let str = ''
                if (_this.cateId == 0) {
                    str += `<li class="mbx-hover">
                <a href="product.html?cateId=0">全部</a>
            </li>`
                } else {
                    str += `<li>
                <a href="product.html?cateId=0">全部</a>
            </li>`
                }

                if (res && res.length > 0) {
                    res.forEach((item, index) => {
                        if (_this.cateId != 0) {

                            if (_this.cateId == item.id) {
                                str += ` <li class="mbx-hover">
                                <a href="product.html?cateId=${item.id}">${item.name}</a>
                            </li>`
                            } else {
                                str += ` <li>
                            <a href="product.html?cateId=${item.id}">${item.name}</a>
                        </li>`
                            }
                        } else {
                            // if (index == 0) {
                            //     str += ` <li class="mbx-hover">
                            //         <a href="product.html?cateId=${item.id}">${item.name}</a>
                            //     </li>`
                            // } else {
                            str += ` <li>
                            <a href="product.html?cateId=${item.id}">${item.name}</a>
                        </li>`
                            // }
                        }

                    })
                }
                $(".pro-catelist-container").html(str)

            },
            err => {
                console.log(err)
            }
        );
    },
    getProductist: function (page) {
        let _this = this;
        console.log('in')
        console.log(common.getQueryString("cateId"))
        _this.cateId = common.getQueryString("cateId") || '0'
        ajax_get(host + `/ajax/productsList/${_this.cateId}/${page}`,
            true,
            {},
            (res) => {
                res = JSON.parse(res)
                console.log(res)
                if (res.list) {
                    _this.renderHtml(res.list)
                    _this.page = res.page
                    _this.renderPageHtml(res)
                }
            },
            err => {
                console.log(err)
            }
        );
    },
    renderHtml(data) {
        let str = ''
        if (data && data.length > 0) {
            data.forEach(item => {
                str += `  <div class="pro-list-li wow fadeInUp">
                <div class="imgJsWrap">
                    <div class="pro-list-img">
                        <a class="img-black cover data3 data-seo3" href="product-detail.html?id=${item.id}">
                            <img src="${item.image}" alt="${item.title}">
                        </a>
                    </div>
                    <div class="pro-list-read">
                        <div class="pro-list-span space-over" title="${item.title}">
                            <a href="product-detail.html">${item.title}</a>
                        </div>
                        <div class="pro-list-span space-list-over">
                            ${item.descript}</div>
                    </div>
                    <div class="pro-border"></div>
                </div>
            </div>`
            });
        } else {
            // str += `<img src="../imgs/about-icon1.png">`
            console.log(str)
        }
        $(".pro-list-ul").html(str)
    },
    renderPageHtml: function (res) {
        let _this = this;
        $('.page-lable-wrap').pagination({
            pageCount: res.page_num,
            current: _this.page,
            coping: false,
            jump: false,
            coping: true,
            homePage: '首页',
            endPage: '末页',
            prevContent: '上页',
            nextContent: '下页',
            callback: function (api) {
                console.log(api)
                _this.page = api.getCurrent()
                _this.getProductist(_this.page)
            }
        });

    }
}


$(function () {
    common.init()
    common.getPhoneInfo()
    common.getBanner("products")
    common.getFootProductCatList()
    common.getFootInfo()
    TechProduct.getProductist(1)
    TechProduct.getProductCatList()
})